package com.jpl.seminar.business.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;

import com.jpl.seminar.business.SeminarService;
import com.jpl.seminar.model.Registration;

public class SeminarServiceImpl implements SeminarService {

	private final EntityManager entityManager;

	public SeminarServiceImpl() {
		this.entityManager = Persistence.createEntityManagerFactory("persistenceUnit").createEntityManager();
	}

	@Override
	public List<Registration> getAllRegistrations() {
		return this.entityManager.createQuery("select r from Registration r", Registration.class).getResultList();
	}

	@Override
	public Long save(Registration registration) {
		this.entityManager.getTransaction().begin();
		this.entityManager.persist(registration);
		this.entityManager.getTransaction().commit();		
		return registration.getId();
	}

}
